package com.qiaoyanqing.ximalaya.discovermodule.discover_activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.qiaoyanqing.ximalaya.R;
import com.qiaoyanqing.ximalaya.discovermodule.discover_adapter.DiscoverRecommendActiLVAdapter;
import com.qiaoyanqing.ximalaya.discovermodule.discover_callback.DiscoverRecommendHotRecommendService;
import com.qiaoyanqing.ximalaya.discovermodule.discover_entity.DiscoverActivityEntity;
import com.qiaoyanqing.ximalaya.url.Urlconfig;
import com.qiaoyanqing.ximalaya.util.MyLog;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class DiscoverRecommendActiActivity extends AppCompatActivity {
    private ListView mListView;
    private DiscoverRecommendActiLVAdapter mAdapter;
    private List<DiscoverActivityEntity.ResultBean>mData=new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_discover_recommend_acti);
        mListView= (ListView) findViewById(R.id.activitylistview);

        initData();



    }

    private void initData() {

        Intent intent=new Intent();

        String url = intent.getStringExtra("url");
        int id=1;

        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl(Urlconfig.RECOACTIVITY)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        DiscoverRecommendHotRecommendService service=retrofit.create(DiscoverRecommendHotRecommendService.class);
        service.getData().enqueue(new Callback<DiscoverActivityEntity>() {
            @Override
            public void onResponse(Call<DiscoverActivityEntity> call, Response<DiscoverActivityEntity> response) {
              //   mData.addAll(response.body());
                MyLog.i("flag","------resopne"+response.body().getMsg());

                mAdapter=new DiscoverRecommendActiLVAdapter(response.body().getResult().getActivityData(),DiscoverRecommendActiActivity.this);
                mListView.setAdapter(mAdapter);


            }

            @Override
            public void onFailure(Call<DiscoverActivityEntity> call, Throwable t) {

            }
        });


    }

    public void backclick(View view) {
        finish();
    }
}
